package com.ming_za.od_updater.core.updater;

import com.ming_za.od_updater.core.window.LoadingState;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 状态桥，用于在更新程序和下载界面进行信息互通
 * 静态存储下载状态
 */
public class StateBridge {

    //更新总数（包括删除）
    private static int total = 0;

    //完成数量
    private static final AtomicInteger completed = new AtomicInteger(0);

    //下载速度-单位：kb/s
    private static int speed = 0;

    //更新状态
    private static UpdateState updateState = UpdateState.SUCCESS;

    //游戏加载状态
    private static LoadingState loadingState = LoadingState.WAITING;

    public static void setLoadingState(LoadingState loadingState) {
        StateBridge.loadingState = loadingState;
    }

    public static int getTotal() {
        return total;
    }

    public static int getCompleted() {
        return completed.get();
    }

    public static int getSpeed() {
        return speed;
    }

    public static UpdateState getUpdateState() {
        return updateState;
    }

    public static void setTotal(int total) {
        StateBridge.total = total;
    }

    public static void setCompleted(int completed) {
        StateBridge.completed.set(completed);
    }

    public static void setSpeed(int speed) {
        StateBridge.speed = speed;
    }

    public static void setUpdateState(UpdateState updateState) {
        StateBridge.updateState = updateState;
    }

    public static void addCompleted() {
        StateBridge.completed.incrementAndGet();
    }

    public static LoadingState getLoadingState() {
        return loadingState;
    }
}
